Skip to content

[Gtk4] Support MenuItem images on GTK4 - #3441

Draft
akurtakov wants to merge 1 commit into
eclipse-platform:masterfrom
akurtakov:gtk4-menu-icons
Draft

[Gtk4] Support MenuItem images on GTK4#3441
akurtakov wants to merge 1 commit into
eclipse-platform:masterfrom
akurtakov:gtk4-menu-icons

Conversation

@akurtakov

Copy link
Copy Markdown
Member

GtkModelButton (GTK4's native menu row) never shows both an icon and text, so PUSH menu items with images rendered without their icon. Work around this by embedding a custom icon+label(+accelerator) GtkButton into the popover via gtk_popover_menu_add_child() for PUSH items.

CASCADE, CHECK and RADIO items keep the native GtkModelButton, since GTK ties their submenu link / selection indicator to it and there is no way to reproduce that in a custom widget.

Injection is self-healing: GTK's "custom" ids are single-use once their placeholder slot is destroyed (e.g. by menu repopulation), so a detached widget is re-injected under a fresh id rather than reusing the stale one, which previously left dynamically-rebuilt items (like Run/Debug) invisible.

WIP towards #2511

@akurtakov
akurtakov marked this pull request as draft July 15, 2026 16:36
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Test Results

  212 files  ±0    212 suites  ±0   29m 51s ⏱️ + 1m 52s
4 953 tests ±0  4 927 ✅ ±0   26 💤 ±0  0 ❌ ±0 
7 151 runs  ±0  6 971 ✅ ±0  180 💤 ±0  0 ❌ ±0 

Results for commit fead2fd. ± Comparison against base commit 203695c.

♻️ This comment has been updated with latest results.

@akurtakov
akurtakov force-pushed the gtk4-menu-icons branch 7 times, most recently from 924149f to 9f101f4 Compare August 4, 2026 07:21
GtkModelButton (GTK4's native menu row) never shows both an icon and
text, so menu items with images rendered without their icon. Work
around this by embedding a custom icon+label(+accelerator) GtkButton
into the popover via gtk_popover_menu_add_child() for PUSH and CHECK
items. The custom row uses the "modelbutton" CSS node so the theme's
menu row rules apply to it, and its icons and the native rows' share
one column via a GtkSizeGroup. CHECK rows carry a GtkCheckButton bound
to the item's action as indicator; CASCADE and RADIO items keep the
native GtkModelButton.

Selection is kept in sync by motion and focus controllers on every
popover: the highlight is re-derived from each row's prelight so it
survives a submenu holding the pointer grab, stray focus selections
are swept, and hovering a sibling closes an open submenu after a short
delay. Themed workbenches (e.g. the e4 dark theme) override the row's
selected background, so the highlight is painted by a display-wide
provider keyed on a class instead.

Injection is self-healing: GTK's "custom" ids are single-use, so a
detached or rebuilt row is re-injected under a fresh id. Menubar
drop-downs are located by their menu model rather than positionally,
avoiding leaks and lost SWT.Show events during item changes.

Contributes to eclipse-platform#2511

Assisted-by: Anthropic Claude Code (claude-sonnet-5)
Assisted-by: Anthropic Claude Code (claude-fable-5-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant